<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script type="text/javascript">
        function calculate(methond,...nums){
            let result;
            if(!methond||nums.length==0){
                alert("请传入参数");
                return;
            }
            if(methond=='*'){
                result=1;
                for(let i=0;i<nums.length;i++){
                    result*=nums[i];
                }
            }else if(methond=='+'){
                result=0;
                for(let i=0;i<nums.length;i++){
                    result+=nums[i];
                }
            }
            alert(result);
        }
        calculate("+",1,2); //3
        calculate("*",1,2,3,4,5)    //15
    </script>
</body>
</html>